package com.gator.spring.framework.aop.aspect;

import com.gator.spring.framework.aop.intercept.PABLO_MethodInterceptor;
import com.gator.spring.framework.aop.intercept.PABLO_MethodInvocation;

import java.lang.reflect.Method;

/**
 * @Author PABLO
 * @Date 2022/5/8 17:28
 * @Desc 异常通知   在执行拦截器链的时候，会依次回调这里的invoke方法
 */
public class PABLO_AfterThrowingAdviceInterceptor
        extends PABLO_AbstractAspectAdvice
        implements PABLO_Advice, PABLO_MethodInterceptor {
    //异常名称
    private String throwingName;
    public PABLO_AfterThrowingAdviceInterceptor(Method aspectMethod, Object aspectTarget) {
        super(aspectMethod, aspectTarget);
    }

    @Override
    public Object invoke(PABLO_MethodInvocation invocation) throws Throwable {
        try {
            return invocation.proceed();
        }catch (Throwable e){
            invokeAdviceMethod(invocation,null,e.getCause());
            throw e;
        }
    }

    public void setThrowName(String throwName){
        this.throwingName = throwName;
    }
}
